<?php 
namespace Admin\Controller;
use \Think\Controller;

class BBStypeController extends Controller
{
	public function index()
	{
		$type = D('Type');
		$data = $type->getAdminCate();
		$this->assign('list',$data);
		$this->display('BBStype/BBStype');

	}
	
	
	//执行添加信息
	public function doadd(){
		$type = D('Type');
		//var_dump($_POST);
		//初始化数据
		if(!$type->create()){
			$this->error($this->_model->getError());
			exit;
		}
		
		//执行添加
		if($type->add()>0){
			$this->success("添加成功!",U('BBStype/index'));
		}else{
			$this->error("添加失败");
		}

	}

	public function del(){
		$type = D('Type');
		//拼装删除条件
		$map['fid'] = array('eq',I('get.tid'));
		$map01['tid'] = array('eq',I('get.tid'));
		
		if($type->where($map)->find()>0){
			$this->error("有子类，不可删除");
		}else{
			$type->where($map01)->delete();
			$this->success("删除成功!",U('BBStype/index'));
		}
	}


	public function doAjax(){
		$type = M('Type');
		$map['tname'] = array('eq',I('get.tname'));
		
		if($type->where($map)->find()){
			$data = '0';
			$this->ajaxReturn($data);
		}
	}



	public function treeList(){
		$type = D('Type');
		$list = $type->getHomeCate();
		$this->assign('list',$list);
		$this->display('BBStype/treeList');
	}



}